



function fushowbox() //显示隐藏层和弹出层
{
    var hideobj = document.getElementById("hidebg");
    hidebg.style.display = "block"; //显示隐藏层
    hidebg.style.height = document.body.clientHeight + "px"; //设置隐藏层的高度为当前页面高度
    document.getElementById("fuhidebox").style.display = "block"; //显示弹出层
}
function fuhidebox() //去除隐藏层和弹出层
{
    document.getElementById("hidebg").style.display = "none";
    document.getElementById("fuhidebox").style.display = "none";
}



function showbox(ele) //显示隐藏层和弹出层
{
    var hideobj = document.getElementById("hidebg");
    hidebg.style.display = "block"; //显示隐藏层
    hidebg.style.height = document.body.clientHeight + "px"; //设置隐藏层的高度为当前页面高度
    document.getElementById("hidebox").style.display = "block"; //显示弹出层
    window.ele = ele.id;
    var idd = window.ele;
    var i = 0;
    var j = 0;
    var tree2 = document.getElementById(idd).getElementsByTagName("li");
    var items = document.getElementById("etim").getElementsByTagName("li");//获取li集合
    for (i = 0; i < items.length; i++) {
        items[i].innerHTML = tree2[i].innerHTML;
    }
}
function hidebox() //去除隐藏层和弹出层
{
    document.getElementById("hidebg").style.display = "none";
    document.getElementById("hidebox").style.display = "none";
}
function myFunction(ele) {

    var idd = window.ele;

    document.getElementById(idd).style.display = "none";//隐藏
    var serverCzId = document.getElementById(idd).childNodes[0].childNodes[1].childNodes[1].childNodes[0].childNodes[0].textContent;
    var serverId = document.getElementById(idd).childNodes[0].childNodes[1].childNodes[1].childNodes[0].childNodes[1].textContent;
    
    var startTime = document.getElementById(idd).childNodes[0].childNodes[1].childNodes[1].childNodes[1].childNodes[1].childNodes[1].textContent;
    var endTime = document.getElementById(idd).childNodes[0].childNodes[1].childNodes[1].childNodes[1].childNodes[2].childNodes[1].textContent;
    // var jsonData=JSON.stringify({'serverId':serverId,'serverCZId':serverCZId,'startTime':startTime,'endTime':endTime});
    var jsonData=JSON.stringify({'serverId':serverId,'serverCzId':serverCzId});
    confirm("确定对该服务器租赁并支付租金？");
    $.ajax({
        type: "post",
        contentType: "application/json",
        url: "http://localhost:8888/zulin/serverZulin",
        async: false,
        data: jsonData,
        dataType: "json",
        headers: { 'Content-Type': 'application/json;charset=utf8', 'token': window.sessionStorage.token },
        success: function (data) {
            if (data.code == 1) {
                alert("支付成功");
            } else {
                alert(data.message);
            }

        }, error: function (data) {
            alert(data.message);
        }
    });



    window.ele = "";

    document.getElementById("hidebg").style.display = "none";
    document.getElementById("hidebox").style.display = "none";
}
function etim(ele) {
    var idd = window.ele;
    var obj_lis = document.getElementById(idd).getElementsByTagName("li");
    for (i = 0; i < obj_lis.length; i++) {
        obj_lis[i].onclick = function () {
            alert(this.innerHTML);
        }
    }
}


function checkIp() {
    var ip = document.getElementById("ip").value;
    //2.定义正则表达式
    var reg_ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
    //3.判断值是否符合正则的规则
    var flag = reg_ip.test(ip);
    if (ip == "") {
        document.getElementById("f_ip").innerHTML = "ip不能为空";
    }
    else {
        if (flag) {
            //提示绿色对勾
            document.getElementById("f_ip").innerHTML = "";
        } else {
            //提示红色错误信息
            document.getElementById("f_ip").innerHTML = "ip输入格式有误";
        }
    }

    // return flag;   
}
function checkUser() {
    var user = document.getElementById("user").value;
    //定义正则表达式
    var reg_user = /^[\u4e00-\u9fa5a-zA-Z]{2,6}$/;///^[\u4e00-\u9fa5]{2,6}$/;/^[\u4e00-\u9fa5a-zA-Z]{1}$/
    //判断值是否符合正则表达式的规则
    var flag = reg_user.test(user);
    //提示信息
    //   var s_name = document.getElementById("s_name");

    if (flag) {
        //提示绿色对勾
        document.getElementById("f_user").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("f_user").innerHTML = "用户名格式有误";
    }
}
function checkUpassword() {
    var upassword = document.getElementById("password").value;
    //2.定义正则表达式
    var reg_upassword = /^\w{6,12}$/;
    //3.判断值是否符合正则的规则
    var flag = reg_upassword.test(upassword);
    if (flag) {
        //提示绿色对勾
        document.getElementById("f_upassword").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("f_upassword").innerHTML = "密码格式有误";
    }
}
function checkReupassword() {
    var upassword = document.getElementById("password").value;
    //2.获取再次输入密码的值
    var reupassword = document.getElementById("reupassword").value;
    //4.提示信息
    //  var s_repassword = document.getElementById("s_repassword");

    if (reupassword == "") {
        document.getElementById("f_reupassword").innerHTML = "不能为空";
        return false;
    }
    else {

        if (upassword == reupassword) {
            //提示绿色对勾
            document.getElementById("f_reupassword").innerHTML = "";
        } else {
            //提示红色错误信息
            document.getElementById("f_reupassword").innerHTML = "密码输入不正确";
        }

    }
}
function checkMery() {

    var mery = document.getElementById("mery").value;
    //2.定义正则表达式
    var reg_mery = /^\d+$|^\d+[.]?\d+$/;
    //3.判断值是否符合正则的规则
    var flag = reg_mery.test(mery);
    if (flag) {
        //提示绿色对勾
        document.getElementById("f_mery").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("f_mery").innerHTML = "请输入数字";
    }
}
function checkDaik() {
    var daik = document.getElementById("daik").value;
    //2.定义正则表达式
    var reg_daik = /^\d+$|^\d+[.]?\d+$/;
    //3.判断值是否符合正则的规则
    var flag = reg_daik.test(daik);
    if (flag) {
        //提示绿色对勾
        document.getElementById("f_daik").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("f_daik").innerHTML = "请输入数字";
    }
}
function checkDisk() {
    var disk = document.getElementById("disk").value;
    //2.定义正则表达式
    var reg_disk = /^\d+$|^\d+[.]?\d+$/;
    //3.判断值是否符合正则的规则
    var flag = reg_disk.test(disk);
    if (flag) {
        //提示绿色对勾
        document.getElementById("f_disk").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("f_disk").innerHTML = "请输入数字";
    }
}
function checkStarTime() {
    var starTime = document.getElementById("starTime").value;
    //2.定义正则表达式
    var reg_startime = /^((?!0000)[0-9]{4}-((0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-8])|(0[13-9]|1[0-2])-(29|30)|(0[13578]|1[02])-31)|([0-9]{2}(0[48]|[2468][048]|[13579][26])|(0[48]|[2468][048]|[13579][26])00)-02-29)$/;
    //3.判断值是否符合正则的规则
    var flag = reg_startime.test(starTime);
    if (flag) {
        //提示绿色对勾
        document.getElementById("f_starTime").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("f_starTime").innerHTML = "请输入正确格式";
    }
}
function checkEndTime() {
    var starTime = document.getElementById("starTime").value;
    var endTime = document.getElementById("endTime").value;
    //2.定义正则表达式
    var reg_endtime = /^((?!0000)[0-9]{4}-((0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-8])|(0[13-9]|1[0-2])-(29|30)|(0[13578]|1[02])-31)|([0-9]{2}(0[48]|[2468][048]|[13579][26])|(0[48]|[2468][048]|[13579][26])00)-02-29)$/;
    //3.判断值是否符合正则的规则
    var flag = reg_endtime.test(endTime);


    var start_unix = Date.parse(starTime); //將字符串格式日期转化为时间戳，就是1970年到当前日期的毫秒数 
    var end_unix = Date.parse(endTime); //將字符串格式日期转化为时间戳，就是1970年到当前日期的毫秒数


    if (flag) {
        //提示绿色对勾
        if (start_unix < end_unix) {
            document.getElementById("f_endTime").innerHTML = "";
        }
        else {
            //提示红色错误信息
            document.getElementById("f_endTime").innerHTML = "请输入正确日期";
        }
    }
    else {
        document.getElementById("f_endTime").innerHTML = "请输入正确格式";
    }

}

function checkMoney() {
    var money = document.getElementById("money").value;
    //2.定义正则表达式
    var reg_money = /^\d+$|^\d*\.\d+$/g;
    //3.判断值是否符合正则的规则
    var flag = reg_money.test(money);
    if (flag) {
        //提示绿色对勾
        document.getElementById("f_money").innerHTML = "";
    } else {
        //提示红色错误信息
        document.getElementById("f_money").innerHTML = "价钱格式有误";
    }

}

function del() {
    var obj = document.getElementById('J_top');
    obj.remove();
}

function serverChuzu() {
    var unindexed_array = $("#chuzu").serializeArray();
    var param = {};
    $.map(unindexed_array, function (n, i) {
        param[n['name']] = n['value'];
    });
    var token = window.sessionStorage.token;
    $.ajax({
        type: "post",
        contentType: "application/json",
        url: "http://localhost:8888/cz/serverChuzu",
        async: false,
        data: JSON.stringify(param),
        dataType: "json",
        headers: { 'Content-Type': 'application/json;charset=utf8', 'token': token },
        success: function (data) {
            if (data.code == 1) {
                alert(data.message);
                fuhidebox();

            } else {
                alert(data.message);
            }

        }, error: function (data) {
            alert(data.message);
        }
    });
}

function serverList() {
    var unindexed_array = $(".search").serializeArray();
    var param = {};
    $.map(unindexed_array, function (n, i) {
        param[n['name']] = n['value'];
    });
    console.log(param[0]);
    $.ajax({
        type: "post",
        contentType: "application/json",
        url: "http://localhost:8888/cz/getServerList",
        async: false,
        data: JSON.stringify(param),
        dataType: "json",
        beforeSend: function (request) {
            request.setRequestHeader("token", sessionStorage.getItem("token"));
        },
        success: function (data) {
            if (data.code == 1) {
                $(".c_houselist").empty()
                var i = 0;
                var list = data.data.objects;
                if (list.length > 0) {
                    for (i = 0; i < list.length; i++) {
                        $(".c_houselist").append("<li class='c_list_item' id='leve" + i + "'  onclick='showbox(this) '>" +
                            "<div class='c_lii'>" +
                            "<div class='item_img'>" +
                            "<img src='../img/1.jpg' width='250' height='170'>" +
                            "</div>" +
                            "<div class='c_right'>" +
                            "<div class='c_item'>" +
                            "<span>&nbsp;&nbsp;&nbsp;&nbsp;详&nbsp;&nbsp;&nbsp;&nbsp;细&nbsp;&nbsp;&nbsp;&nbsp;信&nbsp;&nbsp;&nbsp;&nbsp;息</span>" +
                            "</div>" +
                            "<div class='c_ct' id='c_ct1'>" +
                            "<ul class='xinxi'>" +
                            "<li class='xinxi_li' hidden><span class='serverCZId' hidden>" + list[i].serverCZId + "</span></li>" +
                            "<li class='xinxi_li' hidden><span class='id' hidden>" + list[i].id + "</span></li>" +
                            "<li class='xinxi_li'>单位内存M:<span class='mery'>" + list[i].mery + "</span></li>" +
                            "<li class='xinxi_li'>宽带:<span class='daik'>" + list[i].daik + "</span></li>" +
                            "<li class='xinxi_li'>磁盘处理器:<span class='disk'>" + list[i].disk + "</span></li>" +
                            "</ul>" +
                            "<ul class='xinxi'>" +
                            "<li class='xinxi_li'>地址:<span class='adress'>" + list[i].address + "</span></li>" +
                            "<li class='xinxi_li'>开始时间:<span class='starTime'>" + list[i].starTimeStr + "</span></li>" +
                            "<li class='xinxi_li'>结束时间:<span class='endTime'>" + list[i].endTimeStr + "</span></li>" +
                            "</ul>" +
                            "<ul class='xinxi'>" +
                            "<li class='xinxi_li'>预计出租价格:<span class='mony'>" + list[i].money + "</span></li>" +
                            "</ul>" +
                            "</div>" +
                            "</div>" +
                            "</div>" +
                            "</li>");
                    }
                }
                return;
            } else {
                alert(data.message);
            }

        }, error: function (data) {
            alert(data.message);
        }
    })
}
